package com.hejjon.timer.test;

import java.util.Timer;
import java.util.TimerTask;

/**
 * schedule 和 scheduleAtFixedRate 的区别
 *  schedule 只从当前时间开始执行
 *  scheduleAtFixedRate 会把之前没有来得及执行的任务全都执行
 *
 * Created by caoshi at 8:56 2021-08-15
 */
public class TimerTest4 {

    public static void test4() {
        Timer timer = new Timer("Test4", false);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("schedule");
            }
        }, TimerTest1.getDelayTime(-5), 2000);

        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                System.out.println("scheduleAtFixedRate");
            }
        }, TimerTest1.getDelayTime(-5), 2000);

    }

}
